"""
   cfginit.py, ver 2.2; Phase I
   Ver: 2.1; Rev Last: 08/28/2012, Previous: 08/22/2012 (AEM)

 Rev 2.2.1; Last: 02/12/2013 - Previous: 02/11/2013  (AEM)
   - Clean up to match PEP8 style guide as closely as practical
   - Clean up to match pylint style guide as closely as practical

   Support functions for showtags.py
"""

import sys
#import os
#import datetime
import logging
import wx

CfgFileName = "showtags.cfg"

# ********** Function Definitions **********


def get_cfg_settings():
   """ Read in showtags config settings.
       Config file MUST be named 'showtags.cfg'.

       Config values are name/value pairs separated with
       a '~' symbol in the form of "key~value". The normal '='
       character could not be used due to some values
       containing '=' as a necessary part of the config
       item definition.

       First character of '#' signifies a comment line or disabled
       config value. Line will be skipped.

       Return values as a three value tuple;
       1st value: rtn state: 0 = fail, 1 = success
       2nd value: return message
       3rd value: cfg data as a dictionary
   """

   RtnState = 0
   RtnMssg = ""
   RtnValue = (RtnState, RtnMssg, '')
   ConfigValues = {}

   logging.info("Ready to open and read config file...")
   try:
      for line in open(CfgFileName, 'r'):
         TempStr = line.strip()
         if len(TempStr) > 0 and TempStr[0] != "#":
            (theKey, theValue) = TempStr.split("=")
            ConfigValues[theKey.strip()] = theValue.strip()

      RtnState = 1

   except IOError, (errno, strerror):
      RtnMssg = "Config file open error(%s): %s" % (errno, strerror)
   except:
      RtnMssg = "Unexpected config file open error: ", sys.exc_info()[0]
   finally:
      #RtnMssg += "\nConfig file settings read complete"
      pass

   RtnValue = (RtnState, RtnMssg, ConfigValues)
   return RtnValue
# *************** End of fcn get_cfg_settings ************


# **********************************************
# *** DESIGN NOTE: Add fcn: CheckInitValues(...) to
# ***              - validate integer values
# ***              - Confirm all values supplied
# **********************************************

def OnAboutBox():
   """ About dialog box.

   Example from http://zetcode.com/wxpython/dialogs/
   """

   description = "Show Tags is a free Python open-source application " \
                 "with a GUI-based control interface that provides a " \
                 "skylight into internal music file structural " \
                 "characteristics. The primary mission of Show Tags " \
                 "is to enable viewing and editing select ID3v2.x " \
                 "formatted MP3 music file meta data tags for your own " \
                 "personal use and enjoyment." 

   licence = """Show Tags is free software; you can redistribute 
it and/or modify it under the terms of the GNU General Public License as 
published by the Free Software Foundation; either version 3 of the License, 
or (at your option) any later version.

Show Tags is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License 
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

   info = wx.AboutDialogInfo()

   #info.SetIcon(wx.Icon('gnsimage1.png', wx.BITMAP_TYPE_PNG))
   info.SetName('Show Tags')
   info.SetVersion('2.2.1 (Beta)')
   info.SetDescription(description)
   info.SetCopyright('(C) 2012 - 2013 Arnold Morgan')
   info.SetWebSite(('http://www.byartandbylabor.com', 'ByArtAndByLabor.com'))
   info.SetLicence(licence)
   info.AddDeveloper('Arnold Morgan')
   info.AddDocWriter('Arnold Morgan')
   #info.AddArtist('Arnold Morgan')
   #info.Developers = ["Arnold Morgan"]
   #info.SetArtists(['Arnold Morgan','and others'])
   #info.AddTranslator('Arnold Morgan')

   wx.AboutBox(info)
